﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FinalFantasy6Randomizer
{
    class Ff6Color
    {
        private int red;
        private int green;
        private int blue;

        public int Red
        {
            get { return red; }
            set
            {
                if (0 > value || value > 31)
                    throw new ArgumentOutOfRangeException("value", "Color values must be between 0 and 31 (inclusive.)");

                red = value;
            }
        }

        public int Green
        {
            get { return green; }
            set
            {
                if (0 > value || value > 31)
                    throw new ArgumentOutOfRangeException("value", "Color values must be between 0 and 31 (inclusive.)");

                green = value;
            }
        }

        public int Blue
        {
            get { return blue; }
            set
            {
                if (0 > value || value > 31)
                    throw new ArgumentOutOfRangeException("value", "Color values must be between 0 and 31 (inclusive.)");

                blue = value;
            }
        }

        public byte[] ToRomBytes()
        {
            var intVal = 0;

            intVal |= blue * 1024;
            intVal |= green * 32;
            intVal |= red;

            var retVal = new[]
                             {
                                 (byte) intVal,
                                 (byte)(((uint)intVal >> 8) & 0xFF),
                             };

            return retVal;
        }
    }
}
